$('#reset').click(function(){
    $('input').val('');
})
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];


jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
    var $tab_menu = $(tabBar);
    // 初始化操作
    $tab_menu.removeClass(class_name);
    $(tabBar).eq(i).addClass(class_name);
    $(tabCon).hide();
    $(tabCon).eq(i).show();
    $tab_menu.bind(tabEvent, function () {
        $tab_menu.removeClass(class_name);
        $(this).addClass(class_name);
        var index = $tab_menu.index(this);
        $(tabCon).hide();
        $(tabCon).eq(index).show();
    });
}

$(function () {
    $.Huitab("#tab_goods .tabBar span", "#tab_goods .tabCon", "current", "click", "0")
});


$(function () {
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    })
});

var memberid = sessionStorage.getItem("memberId");

init()
function init() {
    //alert("memberid:"+memberid);
    $.ajax({
        /*root.member.viewMember*/
        url: root.member.viewCustInfoRegisterForm,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "memberId":memberid
        }),
        success: function (data) {
            console.log(data);
            console.log(data.custInfoRegisterForm);
            $('#memberId').val(data.custInfoRegisterForm.memberId);
            var typeobj = document.getElementById("type");//select
            var typeValue=data.custInfoRegisterForm.type;//之前选中的
            //设置选中的值
            for(var i=0; i<typeobj.options.length; i++){
                if(typeobj.options[i].value == typeValue){
                    typeobj.options[i].selected = true;
                    break;
                }
            }
            $('#name').val(data.custInfoRegisterForm.name);
            $('#linkName').val(data.custInfoRegisterForm.linkName);

            $('#position').val(data.custInfoRegisterForm.position);
            $('#mobile').val(data.custInfoRegisterForm.mobile);
            $('#officePhone').val(data.custInfoRegisterForm.officePhone);
            $('#companyRegAddress').val(data.custInfoRegisterForm.companyRegAddress);
            $('#companyOfficeAddress').val(data.custInfoRegisterForm.companyOfficeAddress);
            $('#storeArea').val(data.custInfoRegisterForm.storeArea);
            $('#projectName').val(data.custInfoRegisterForm.projectName);
            $('#projectAddress').val(data.custInfoRegisterForm.projectAddress);
            var cooperationPotentialobj = document.getElementById("cooperationPotential");
            var cooperationPotentialValue=data.custInfoRegisterForm.cooperationPotential;//之前选中的
            //设置选中的值
            for(var i=0; i<cooperationPotentialobj.options.length; i++){
                if(cooperationPotentialobj.options[i].value == cooperationPotentialValue){
                    cooperationPotentialobj.options[i].selected = true;
                    break;
                }
            }
            $('#situationDesc').val(data.custInfoRegisterForm.situationDesc);
        },
        error: function () {
            $.Huimodalalert('失败！');
        }
    });
}
//获取操作人的姓名及ID
var loginData = JSON.parse(web.readCookie("loginData"));
//var username = loginData.user.username;
//var user_ID = loginData.user.user_ID;
function save_edit() {
    //alert("119999999"+loginData.user.name);
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        /*root.member.updateMemberStatus*/
        url:root.member.updateCustInfoRegisterForm,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify({
            memberId:$("#memberId").val(),
            type:$('#type option:selected') .val(),//$("#type").val(),
            name:$("#name").val(),
            linkName:$("#linkName").val(),
            position:$("#position").val(),
            mobile:$("#mobile").val(),
            officePhone:$("#officePhone").val(),
            companyRegAddress:$("#companyRegAddress").val(),
            companyOfficeAddress:$("#companyOfficeAddress").val(),
            storeArea:$("#storeArea").val(),
            projectName:$("#projectName").val(),
            projectAddress:$("#projectAddress").val(),
            cooperationPotential:$('#cooperationPotential option:selected') .val(),//$("#cooperationPotential").val(),
            situationDesc:$("#situationDesc").val(),

            updateUserId: loginData.user.user_ID,//登录人id
            updateUserName: loginData.user.username,//登录人名称

        }),
        success: function (data) {
            console.log(data)
            if(0==data.errorCode) {
                layer.msg('操作成功!', {icon: 6, time: 1000});
                setTimeout( function () {
                    var index = parent.location.reload();
                    parent.layer.close(index);
                },700);
            }else{
                //其它错误
                layer.msg(data.errorMessage, {icon: 6, time: 3000});
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}

function removeIframe(){
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}




